package com.deviche.library.net;


import com.deviche.library.Constant;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;


public class NetHelper {

    public static final long DEFAULT_TIME_OUT = 5L;

    private static Retrofit retrofit;
    private static OkHttpClient httpClient;

    public static void init() {

        httpClient = new OkHttpClient.Builder()
//                .addNetworkInterceptor(null)
                .readTimeout(DEFAULT_TIME_OUT, TimeUnit.SECONDS)
//                .addInterceptor(null)
                .retryOnConnectionFailure(true)
                .build();

        retrofit = new Retrofit.Builder()
                .baseUrl(Constant.BASE_URL)
                .client(httpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build()
                ;
    }

    public static Retrofit getRetrofit() {
        return retrofit;
    }

}
